<?php 
session_cache_expire(999999999);
if(!isset($_SESSION)) 
{ 
	session_start(); 
}
$lang = $_SESSION['lang'];
if (empty($lang) || $lang == "EN") {
	include "../value/value_en.php";
} else if($lang == "VN") {
	include "../value/value_vn.php";
}
else {
	include "../value/value_kr.php";
}

$mang=$_SESSION['inputMoneys'];
include '../operations/connection.php';	

foreach ($mang as $value => $giatri){
	$giatri[3]=str_replace(",","",$giatri[3]);
	$d=split('-',$giatri[2]);
	$kq = mysql_query("SELECT * from LogMoney l where l.idcategory =".$giatri[0]." AND MONTH(l.datetime)='".$d[1]."' AND YEAR(l.datetime)='".$d[0]."'");
	if(mysql_num_rows($kq)>=1)
		$sql=("UPDATE `LogMoney` SET `money`='".$giatri[3]."',`status`='".$giatri[4]."',`method`='".$giatri[5]."',`note`='".$giatri[6]."' WHERE `idcategory`='".$giatri[0]."' AND MONTH(datetime)='".$d[1]."' AND YEAR(datetime)='".$d[0]."'");
	else
		$sql=("INSERT INTO `LogMoney` (`idcategory`, `datetime`, `money`,`status`,`method`,`note`) VALUES ('".$giatri[0]."', '".$giatri[2]."', '".$giatri[3]."', '".$giatri[4]."', '".$giatri[5]."', '".$giatri[6]."')");
	mysql_query($sql);
	//echo $sql;		
}
unset($_SESSION['inputMoneys']);
mysql_close($connection);
?>
